function ajax (url) {
  return new Promise(function(resolve,reject) {
    var xhr = new XMLHttpRequest()
    xhr.open('GET',url)
    xhr.responseType = 'json'
    xhr.onload = function() {
      // 请求完成
      if(this.status === 200){ 
        resolve(this.response)
      } else {
        reject(new Error(this.statusText))
      }
    }
    xhr.send()
  })
}

ajax('/api/users.json').then(function(value){
  console.log('resolved',value);
},function(error){
  console.log('rejected',error);
})